package com.anolesoft.yr.mbus.base.mapper;

import com.anolesoft.yr.mbus.base.entity.BaseRegionTreeQueryDO;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * @author zhj
 * @date 2020/8/7 16:53
 */
@Mapper
public interface BaseRegionTreeQueryMapper {
    @Results(id = "BaseRegionTreeQueryResultMap", value = {
            @Result(id = true, column = "objuid", property = "objuid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "region_code", property = "regionCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "region_level", property = "regionLevel", jdbcType = JdbcType.VARCHAR),
            @Result(column = "region_name", property = "regionName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "parent_uid", property = "parentUid", jdbcType = JdbcType.VARCHAR),
            @Result(column = "fac_code", property = "factoryCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "objuid", property = "children", many=@Many(select = "com.anolesoft.yr.mbus.base.mapper.BaseRegionTreeQueryMapper.selectTree",fetchType = FetchType.LAZY))
    })
    @Select("select " +
            "objuid, region_code, region_level, region_name, parent_uid, fac_code   " +
            "from base_region where del_flag = 0 and parent_uid = #{parentId,jdbcType=VARCHAR} ")
    List<BaseRegionTreeQueryDO> selectTree(@Param("parentId") String parentId);
}
